// import  axios  from "axios";
import { setToken, clearToken } from "@/utils"
import { loginApi } from "@/api/login"
import { LOGIN_TOKEN, LOGOUT } from "../constants"
export const login = (mobile, code) => {
  return async (dispatch) => {
    // const res = await axios.post('http://geek.itheima.net/v1_0/authorizations',{
    //   mobile,
    //   code
    // })
    const res = await loginApi(mobile, code)
    const { token } = res.data.data
    dispatch({ type: LOGIN_TOKEN, payload: token })
    // localStorage.setItem('tcast_geek_pc',token)
    setToken(token)
  }
}

export const logout = () => {
  return (dispatch) => {
    dispatch({ type: LOGOUT })
    clearToken()
  }
}
